package com.uphone.edwards.pro.activity.login.catalogue;

import android.arch.lifecycle.LifecycleOwner;

import com.blankj.utilcode.util.ToastUtils;
import com.radish.baselibrary.utils.LogUtils;
import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;
import com.uphone.edwards.MyApp;
import com.uphone.edwards.base.mvp.BasePAV;
import com.uphone.edwards.http.ApiService;
import com.uphone.edwards.http.RxSchedulers;
import com.uphone.edwards.pro.activity.login.mine.MineContract;

import org.json.JSONObject;

import javax.inject.Inject;

public class CataLoguePresenter extends BasePAV<CataLogueContract.View> implements CataLogueContract.Presenter {

    @Inject
    CataLoguePresenter() {

    }

    @Override
    public void postManual() {
        mView.showLoading();
//        Map<String, String> map = new HashMap<>();
//        map.put("langId", "2");
        MyApp.apiService(ApiService.class)
                .getContents("" , MyApp.languageType)
                .compose(RxSchedulers.io_main())
                .as(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from((LifecycleOwner) mView)))
                .subscribe(bean -> {
                    mView.closeLoading();
                    if (bean != null) {
                        try {
                            String add = bean.string();
                            LogUtils.e("====" + add);

                            JSONObject jsonObject = new JSONObject(add);
                            int status = jsonObject.getInt("code");
                            LogUtils.e("status:" + status + "  responseBean:" + bean.string());
                            if (status != 1) {
                                ToastUtils.showShort(jsonObject.getString("msg"));
                            }
                            mView.manualView(add , status);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }, throwable -> {
                    mView.closeLoading();
                    mView.onFail();
                });
    }

}
